//
//  GDImage.h
//  GDFramework
//
//  Created by David Thorpe on 2007-07-20.
//  Copyright 2007 David Thorpe. All rights reserved.
//
//  Modified by David Rudie on 2009-05-09.
//  Modified and added functions by David Rudie are under the
//  following license:
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#import <Foundation/Foundation.h>
#import "GDTypes.h"
#import "GDColor.h"
#import "GDFont.h"


// GDImage
@interface GDImage : NSObject {
	void *m_theImagePtr;
}

// constructors for images
- (id)initWithSize:(NSSize)theSize;
- (id)initWithData:(NSData *)theData;
- (id)initWithFile:(NSString *)thePath;

// guess what type of image
+ (GDImageType)typeForFilename:(NSString *)thePath;
+ (GDImageType)typeForMimetype:(NSString *)theMimetype;
+ (GDImageType)typeForData:(NSData *)theData;
+ (GDImageType)typeForFile:(NSString *)thePath;

// create data blobs for images, write out images
// when writing JPEG's, the 'quality' setting should be between 0.0 and 1.0
- (BOOL)writeToFile:(NSString *)thePath type:(GDImageType)theImageType;
- (BOOL)writeToFile:(NSString *)thePath type:(GDImageType)theImageType quality:(CGFloat)theQuality;
- (NSData *)dataForType:(GDImageType)theImageType;
- (NSData *)dataForType:(GDImageType)theImageType quality:(CGFloat)theQuality;

// get dimensions of image
- (CGFloat)width;
- (CGFloat)height;
- (NSSize)size;

// create new image by resizing and constraining
- (GDImage *)imageResizedTo:(NSSize)theSize resampled:(BOOL)isResampled;
- (GDImage *)imageCroppedTo:(NSRect)theRect resampled:(BOOL)isResampled;
- (GDImage *)imageConstrainedToMaxSize:(NSSize)theSize resampled:(BOOL)isResampled;
- (GDImage *)imageConstrainedToMinSize:(NSSize)theSize resampled:(BOOL)isResampled;
- (GDImage *)imageConstrainedToSize:(NSSize)theSize resampled:(BOOL)isResampled cropped:(NSInteger)flags;

// retrieving colours from image, components are all 0.0->1.0
- (GDColor *)colorForPoint:(NSPoint)thePoint;
- (GDColor *)colorForRed:(CGFloat)theRed green:(CGFloat)theGreen blue:(CGFloat)theBlue;
- (GDColor *)colorForRed:(CGFloat)theRed green:(CGFloat)theGreen blue:(CGFloat)theBlue alpha:(CGFloat)theAlpha;

// drawing into an image
- (void)drawRectFill:(NSRect)theRect withColor:(GDColor *)theColor;
- (void)drawRectOutline:(NSRect)theRect withColor:(GDColor *)theColor;
- (void)drawLineFrom:(NSPoint)theSource to:(NSPoint)theDest withColor:(GDColor *)theColor;
- (void)drawImage:(GDImage *)theImage intoRect:(NSRect)theRect;
- (void)drawString:(NSString *)theString point:(NSPoint)thePoint font:(GDFont *)theFont color:(GDColor *)theColor;

// filtering the image
- (void)filterSharpenBy:(CGFloat)theAmount;

// Subpixel Resample function -- David Rudie
- (GDImage *)imageSubpixelConstrainedToSize:(NSSize)theSize cropped:(NSInteger)flags cropRatio:(NSNumber *)theCropRatio;
- (CGFloat)clampColor:(CGFloat)theColor;
- (void)mergeImage:(GDImage *)theImage textPosition:(NSInteger)theTextPosition sourceYPoint:(NSInteger)theSourceYPoint width:(CGFloat)theWidth;

@end